<?php
/**
 * Registering meta boxes
 *
 * All the definitions of meta boxes are listed below with comments.
 * Please read them CAREFULLY.
 *
 * You also should read the changelog to know what has been changed before updating.
 *
 * For more information, please visit: 
 * @link http://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
 */

/********************* META BOX DEFINITIONS ***********************/

/**
 * Prefix of meta keys (optional)
 * Use underscore (_) at the beginning to make keys hidden
 * Alt.: You also can make prefix empty to disable it
 */
// Better has an underscore as last sign
$prefix = 'locality_';


/*-----------------------------------------------------------------------------------*/  
/*------------------	        Meta Box for Page sub title            --------------*/
/*-----------------------------------------------------------------------------------*/
global $meta_boxes;

$meta_boxes = array();

// meta box Property images
/*$meta_boxes[] = array(
	'id'		=> 'subtitles',
	'title'		=> __('Sub Title For This Page','locality'),
	'pages' => array('page'),

	'fields'	=> array(
		array(
			'name'	=> __('Page Sub Title', 'locality'),
			'desc'	=> __('Add 3 to 5 words Discription that will be shown as Sub title of this page.', 'locality'),
			'id'	=> "{$prefix}page_subtitle",
			'type'	=> 'text'
		)
	)
);
*/

/*-----------------------------------------------------------------------------------*/  
/*------------------	    Metabox for Single Page Image Upload and Sub Title        --------------*/
/*-----------------------------------------------------------------------------------*/
$meta_boxes[] = array(
	'id'		=> 'page_data_box',
	'title'		=> __('Additional Data Box','locality'),
	'pages' => array( 'page'),

	'fields'	=> array(
		
		array(
			'name'	=> __('Page Sub Title', 'locality'),
			'desc'	=> __('Add 3 to 5 words Discription that will be shown as Sub title of this page.', 'locality'),
			'id'	=> "{$prefix}page_subtitle",
			'type'	=> 'text'
		),
		array(
			'name'	=> __('Banner Image', 'locality'),
			'desc'	=> __('Upload the banner image here. Banner Image should have 715px width and 143px height.', 'locality'),
			'id'	=> "{$prefix}banner_image",
			'type'	=> 'image'
		)
	)
);


/*-----------------------------------------------------------------------------------*/  
/*------------------	    Metabox for property images                --------------*/
/*-----------------------------------------------------------------------------------*/
$meta_boxes[] = array(
	'id'		=> 'propertyview',
	'title'		=> __('Property Images','locality'),
	'pages' => array( 'property'),

	'fields'	=> array(

		// NEW(!) PLUPLOAD IMAGE UPLOAD (WP 3.3+)
		array(
			'name'	=> __('Property Pictures', 'locality'),
			'desc'	=> __('Add 6 or (multiple of 6) property photos, it will be showon at Propery Detail page as gallery.', 'locality'),
			'id'	=> "{$prefix}property_pictures",
			'type'	=> 'plupload_image'
		)
	)
);


/*-----------------------------------------------------------------------------------*/  
/*------------------	        Proptery Features                      --------------*/
/*-----------------------------------------------------------------------------------*/
$meta_boxes[] = array(
	'id'		=> 'property_details',
	'title'		=> __('Property Details','locality'),
	'pages' => array( 'property'),

	'fields'	=> array(
		
		array(
			'name'		=> __('Status','locality'),
			'id'		=> "{$prefix}status",
			'type'		=> 'select',
			'options'	=> array(			  	
				'for-rent'		=> __('For Rent','locality'),
				'for-sale'		=> __('For Sale','locality'),
				'new'		=> __('New','locality'),
				'onshow'		=> __('On Show','locality'),
				'sold'		=> __('Sold','locality'),
				'reduced'		=> __('Reduced','locality'),
				'none'		=> __('No Tag','locality'),
			),
			'std'		=> array( '' ),
			'desc'		=> __('Choose For Rent or For Sale or any other given option.','locality')
		),

		// Price
		array(
			'name'	=> __('Price', 'locality'),
			'desc'	=> __('Example: 345600 . Please add price without commas.', 'locality'),
			'id'		=> "{$prefix}property_price",
			'type'		=> 'text',
			'std'		=> "00000"
		),
		// Size
		array(
			'name'	=> __('Size', 'locality'),
			'desc'	=> __('Example: 1520', 'locality'),
			'id'		=> "{$prefix}property_size",
			'type'		=> 'text',
			'std'		=> "00"
		),
		// Number of Bed Rooms
		array(
			'name'	=> __('Bed Rooms', 'locality'),
			'desc'	=> __('Example: 4', 'locality'),
			'id'		=> "{$prefix}property_bedrooms",
			'type'		=> 'text',
			'std'		=> "0"
		),
		// Number of sss Rooms
		array(
			'name'	=> __('Bath Rooms', 'locality'),
			'desc'	=> __('Example: 2', 'locality'),
			'id'		=> "{$prefix}property_bathrooms",
			'type'		=> 'text',
			'std'		=> "0"
		),
		// Number of Garage
		array(
			'name'	=> __('Garage', 'locality'),
			'desc'	=> __('Example: 1', 'locality'),
			'id'		=> "{$prefix}garage",
			'type'		=> 'text',
			'std'		=> "0"
		),
		// Furnishing Option
		array(
			'name'	=> __('Furnishing', 'locality'),
			'type'		=> 'select',
			'options'	=> array(
			  	'Furnished' => __('Furnished','locality'),
				'Unfurnish' => __('Unfurnished','locality')
			),
			'std'		=> array( '' ),
			'desc'	=> __('', 'locality'),
			'id'		=> "{$prefix}furnish"
		),
		// Mortgage Option
		array(
			'name'	=> __('Mortgage', 'locality'),
			'type'		=> 'select',
			'options'	=> array(
			  	'Mortgage' => __('Mortgage','locality'),
				'NoMortgage' => __('NoMortgage','locality')
			),
			'desc'	=> __('', 'locality'),
			'id'		=> "{$prefix}mortgage",
			'std'		=> array( '' )
		),
		// Date 
		array(
			'name'	=> __('Date of availibility', 'locality'),
			'id'		=> "{$prefix}date",
			'type'		=> 'date', // Date format, default yy-mm-dd. Optional. See: http://goo.gl/po8vf
			'format'	=> 'd MM, yy'
		),
		// Property Location Map
		array(
			'name'	=> __('Property Location at Google Map', 'locality'),
			'desc'	=> __('Enter Valid Google Map Address', 'locality'),
			'id'		=> "{$prefix}property_location",
			'type'		=> 'text',
			'std'		=> ""
		),
		// Virtual Tour Video
		array(
			'name'	=> __('Virtual Tuor YouTube Video', 'locality'),
			'desc'	=> __('Enter Youtube Video ID -------- For example: "1iIZeIy7TqM" is ID of this video: "http://www.youtube.com/watch?v=1iIZeIy7TqM"', 'locality'),
			'id'		=> "{$prefix}youtube_link",
			'type'		=> 'text',
			'std'		=> ""
		),		
		// Featured Post
		array(
			'name'	=> __('Make this Property Featured', 'locality'),
			'id'		=> "{$prefix}featured",
			'type'		=> 'checkbox',
			'desc'		=> 'Making this Property Featured will display this propery in Homepage Slider and Sidebar Featured Property Widget.',
			'std'		=> 1
		),
	)
);


/********************* META BOX REGISTERING ***********************/

/**
 * Register meta boxes
 *
 * @return void
 */
function locality_register_meta_boxes()
{
	global $meta_boxes;

	// Make sure there's no errors when the plugin is deactivated or during upgrade
	if ( class_exists( 'RW_Meta_Box' ) )
	{
		foreach ( $meta_boxes as $meta_box )
		{
			new RW_Meta_Box( $meta_box );
		}
	}
}
// Hook to 'admin_init' to make sure the meta box class is loaded
//  before (in case using the meta box class in another plugin)
// This is also helpful for some conditionals like checking page template, categories, etc.
add_action( 'admin_init', 'locality_register_meta_boxes' );


